﻿//
// Gns_TwoCodeWnd.cpp
//
//
// Created by yjf
//
//

#include "Gns_AccessWnd.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"

USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()


enum 
{
	BTN_TAKE,			//取分
	BTN_STORE,			//存分
};


Gns_AccessWnd::Gns_AccessWnd()
{
   
}

Gns_AccessWnd::~Gns_AccessWnd()
{
    
}

Gns_AccessWnd* Gns_AccessWnd::Create(string csbName,MOVABLE_TYPE showType, MOVABLE_TYPE hideType)
{
	auto wnd = new Gns_AccessWnd();

	if (wnd && wnd->init(csbName,showType,hideType))
	{
		wnd->autorelease();
	}
	else
	{
		CC_SAFE_DELETE(wnd);
		wnd = nullptr;
	}
	
    
	return wnd;
}

bool Gns_AccessWnd::init(string csbName, MOVABLE_TYPE showType, MOVABLE_TYPE hideType)
{
	if (!PopWnd::init(csbName))
	{
		return false;
	}

	_tShowType = showType;
	_tHideType = hideType;

	auto takePoint = static_cast<Button *>(_rootNode->getChildByName("Button_2"));	    //取分
	takePoint->addTouchEventListener(CC_CALLBACK_2(Gns_AccessWnd::doEvent, this));
	takePoint->setTag(BTN_TAKE);

	auto storePoint = static_cast<Button *>(_rootNode->getChildByName("Button_1"));	//存分
	storePoint->addTouchEventListener(CC_CALLBACK_2(Gns_AccessWnd::doEvent, this));
	storePoint->setTag(BTN_STORE);

	return true;
}

void Gns_AccessWnd::doEvent(cocos2d::Ref *pSender, ui::Widget::TouchEventType type)
{
    if (type==ui::Widget::TouchEventType::ENDED) 
	{
        auto pButton = (Button*)pSender;
        int BtnTag = pButton->getTag();
        switch (BtnTag) 
		{
			case BTN_TAKE:
            {
               
				Show(false);
                break;
            }
			case BTN_STORE:
            {
				Show(false);
				break;
            }
            default:
                break;
        }
    }
}

int Gns_AccessWnd::getNumFromEditBox()
{
	auto box = (TextField*)_rootNode->getChildByName("TextField_2");
	auto str = box->getString();

	return atoi(str.c_str());
}

void Gns_AccessWnd::sendTAKEPOINT()
{

}

void Gns_AccessWnd::sendSTOREPOINT()
{

}

